package cn.dxh.stagefinal.service.impl;

import cn.dxh.stagefinal.bean.Employee;
import cn.dxh.stagefinal.bean.Order;
import cn.dxh.stagefinal.dao.OrderDao;
import cn.dxh.stagefinal.service.OrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderDao orderDao;

    @Override
    public PageInfo<Order> findAll(Integer pageindex, Integer size, String
            ordernum, String source, String orderdate, String username,Integer state) {
        PageHelper.startPage(pageindex,size);
        Map map = new HashMap();
        map.put("ordernum",ordernum);
        map.put("source",source);
        map.put("orderdate",orderdate);
        map.put("username",username);
        map.put("state",state);
        List<Order> orderList = orderDao.findAll(map);
        PageInfo<Order> pageInfo = new PageInfo<>(orderList);
        return pageInfo;
    }

    @Override
    public Order getOne(Integer orderid) {
        return orderDao.getOne(orderid);
    }

    @Override
    public List<Employee> finddelivery() {
        return orderDao.finddelivery();
    }

    @Override
    public Integer choose(String eName, Integer orderid) {
        Map map = new HashMap();
        map.put("eName",eName);
        map.put("orderid",orderid);
        return orderDao.choose(map);
    }

    @Override
    public Integer sendgoods(Integer orderid,Integer orderstate) {
        Map map = new HashMap();
        map.put("orderid",orderid);
        map.put("orderstate",orderstate);
        return orderDao.sendgoods(map);
    }

    @Override
    public PageInfo<Order> findsend(Integer pageindex, int pageSize, String ordernum, String source, String orderdate, String username, Integer[] orderstate,String deliveryman) {
        Map map = new HashMap();
        map.put("ordernum",ordernum);
        map.put("source",source);
        map.put("orderdate",orderdate);
        map.put("username",username);
        map.put("orderstate",orderstate);
        map.put("deliveryman",deliveryman);
        PageHelper.startPage(pageindex,pageSize);
        List<Order> findsend = orderDao.findsend(map);
        PageInfo<Order> pageInfo = new PageInfo<>(findsend);
        return pageInfo;
    }

    @Override
    public Integer chooseids(String eName, Integer[] orderids) {
        Map map = new HashMap();
        map.put("eName",eName);
        map.put("orderids",orderids);
        return orderDao.chooseids(map);
    }

    @Override
    public Employee getRole(Integer eid) {
        return orderDao.getRole(eid);
    }

    @Override
    public List<Order> export() {
        return orderDao.export();
    }
}
